#include "Channel.h"
#include "Eventloop.h"


namespace liu
{
	Channel::Channel(Eventloop* ploop, int fd)
		:m_pLoop(ploop),m_fd(fd)
	{
		RUN_TRACE;
		cout << debug_time() << "Create Channel instance with fd:[" << m_fd << "]." << endl;
	}

	Channel::~Channel()
	{

	}

	void Channel::handleEvent()
	{
		RUN_TRACE;
		if (m_revents & (EPOLLIN | EPOLLPRI | EPOLLRDHUP))
		{
			cout << debug_time() << "Channel::handleEvent read callback." << endl;

			if (m_readCallback)
			{
				m_readCallback();
			}
		}
		if (m_revents & EPOLLOUT)
		{
			cout << debug_time() << "Channel::handleEvent write callback." << endl;
			if (m_writeCallback)
			{
				m_writeCallback();
			}
					
		}
	}

	void Channel::update()
	{
		RUN_TRACE;
		m_pLoop->UpdateChannel(this);
	}

}
